Component({
  attached() {
    this.setPaddingTop();
    this.getUser();
    this.msgCompute();
  },
  /**
   * 页面的初始数据
   */
  data: {
    user: null,
    paddingTop: 0,
    topMenu: [{
      label: "我的发布",
      path: "/pages/my/myrelease/myrelease", //跳转地址
      icon: "../../../../static/my/mail_1@3x.png",
    }, {
      label: "收藏",
      path: "/pages/my/mycollect/mycollect", //跳转地址 
      icon: "../../../../static/my/Frame_48096455@3x.png",
    }, {
      label: "浏览历史",
      path: "/pages/my/browsinghistory/browsinghistory", //跳转地址
      icon: "../../../../static/my/mail_2@3x.png",
    }],
    list: [{
      title: "我的交易",
      url: "../../../../static/my/order.png"
    }, {
      title: "平台交易流程",
      url: "../../../../static/my/flow.png"

    }, {
      title: "联系客服",
      url: "../../../../static/my/customerservice.png"

    }, {
      title: "公众号",
      url: "../../../../static/my/wechat.png"

    }],
    newMsgCount: 0
  },
  methods: {
    // 获取信息条数
    async msgCompute() {
      let res = await getApp().http.iCenterConter()
      if (res.data) {
        this.setData({
          newMsgCount: res.data.newMsgCount,
        })
      }
    },
    goMsg() {
      wx.navigateTo({
        url: '/pages/message/message',
      })
    },
    goAuthentication() {
      wx.navigateTo({
        url: '/pages/my/authentication/authentication',
      })
    },
    // 点击头像
    navAvatar() {
      if (this.data.user) {
        wx.navigateTo({
          url: '/pages/my/center/center',
        })
      } else {
        // 前往登录
        this.goLogin();
      }
    },
    // 获取用户信息
    getUser() {
      const currentUser = wx.getStorageSync('currentUser');
      this.setData({
        user: currentUser ?? null
      })
    },
    goMenuTab(e) {
      const path = e.currentTarget.dataset.path
      if (path) {
        getApp().nav.navTo({
          url: path,
        })
      } else {
        wx.showToast({
          title: '暂无跳转地址',
          icon: "none"
        })
      }
      console.log(e.currentTarget.dataset.path);
    },
    goLogin() {
      getApp().nav.navTo({
        url: '/pages/login/login',
      })
    },
    setPaddingTop() {
      let navStyle = getApp().globalData.view;
      console.log(navStyle.titleTopDistance + "px")
      this.setData({
        paddingTop: navStyle.navStatusBarHeight + "px"
      })
    }
  }
})